/**
 * @class   wosh::communication::ContactInfo
 * @brief   
 *
 *
 *
 ****************************************************************************
 * @version 0.8.499 $Id: ContactInfo.h 2877 2010-08-09 00:02:53Z alex $
 * @author  Alessandro Polo
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/


#ifndef __WOSH_ContactInfo_H__
 #define __WOSH_ContactInfo_H__

 #include <woshDefs.h>
 #include <core/Serialization.h>
 #include <core/Notification.h>
 #include <core/User.h>


namespace wosh {
 template <class T> class DataFieldCollector;
 namespace communication {

class SessionProxy;

class ContactInfo : public virtual ISerializable
 {
	WOSH_SERIALIZABLE(wosh::communication::ContactInfo)
	WOSH_COMPARE_RTTI(wosh::communication::ContactInfo)


	public:
		/**
		 * @brief  Empty constructor.
		 */
		ContactInfo();
		/**
		 * @brief  Copy constructor.
		 * @param m [in] the source object to be copied
		 */
		ContactInfo( const ContactInfo& m );
		/**
		 * @brief  Empty destructor.
		 */
		virtual ~ContactInfo() { }

//@}
/** @name Setters
 * @{
 ******************************************************************************/
	public:
		void setUserID( const std::string& value )			{ this->userID = value; }

		void setUser( const std::string& value )			{ this->userWosh = value; }

		void setLastSeen( long value )						{ this->lastSeen = value; }

		void setProtocol( Notification::PROTOCOL pr )		{ this->protocol = pr; }

		void setLanguage( const std::string& value )		{ this->language = value; }

		void setLastTargetUser( const std::string& value )	{ this->lastTargetWoshUser = value; }

		void setStatusMessage( const std::string& value )	{ this->statusMsg = value; }
		
		void setUserPresence( User::PRESENCE value )		{ this->presence = value; }
		void setUserStatus( User::STATUS value )			{ this->status = value; }

		void set( const std::string& custom_user, const std::string& wosh_user, long last_seen );

		void setLastSeen();

		virtual void clear();

		void setSession( SessionProxy* session_ptr )		{ this->session = session_ptr; }

//@}
/** @name Getters
 * @{
 ******************************************************************************/
	public:
		inline const std::string& getUserID() const			{ return this->userID; }

		inline const std::string& getUser() const			{ return this->userWosh; }

		inline long getLastSeen() const						{ return this->lastSeen; }

		inline Notification::PROTOCOL getProtocol() const	{ return this->protocol; }

		inline const std::string& getLanguage() const		{ return this->language; }

		inline const std::string& getLastTargetUser() const	{ return this->lastTargetWoshUser; }

		inline const std::string& getStatusMessage() const	{ return this->statusMsg; }

		inline User::PRESENCE getUserPresence() const		{ return this->presence; }
		inline User::STATUS getUserStatus() const			{ return this->status; }

		virtual inline bool isUserSetAndSeen() const		{ return (!this->userWosh.empty() && this->lastSeen > 0); }

		bool isTimedOut( long seconds ) const;

		virtual inline bool isOnline() const				{ return (this->lastSeen > 0); }
		virtual inline bool isOffline() const				{ return (this->lastSeen <= 0); }

		inline const char* getUserPresenceAsString() const	{ return User::getUserPresenceAsString(this->presence); }
		inline const char* getUserStatusAsString() const	{ return User::getUserStatusAsString(this->status); }

		SessionProxy* getSession()							{ return this->session; }

		static DataFieldCollector<ContactInfo>* getDataFields();

//@}
/** @name Operators Overloading
 * @{
 ******************************************************************************/
	public:
		virtual ContactInfo& operator=(const ContactInfo& m);
		virtual bool operator==(const ContactInfo &other) const;
		virtual bool operator!=(const ContactInfo &other) const	{ return !(*this == other);  }
		virtual bool operator>(const ContactInfo& other) const	{ return (this->userWosh > other.userWosh); }
		virtual bool operator<(const ContactInfo& other) const	{ return (this->userWosh < other.userWosh); }
//@}
/** @name Serialization interface
 * @{
 ******************************************************************************/
	public:
		virtual std::string toString() const;
		virtual bool updateHash( DataHashContext* hash_context ) const;
//@}
	protected:
		std::string userID;					///< custom account name
		std::string userWosh;				///< wosh account name
		long lastSeen;						///< negative long value means is actuall offline, use abs() to get epoch
		std::string statusMsg;

		User::PRESENCE presence;
		User::STATUS status;

		Notification::PROTOCOL protocol;	///< current protocol
		std::string language;				///< current language
		std::string lastTargetWoshUser;		///< wosh account name

		SessionProxy* session;

}; // class def


 }; // namespace communication
}; // namespace wosh

#endif //__WOSH_ContactInfo_H__
